package com.greenantmall.activity.fragment;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.app.Fragment;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.avos.avoscloud.AVUser;
import com.greenantmall.AntHomeApplication;
import com.greenantmall.R;
import com.greenantmall.adapter.PortalListViewAdapter;
import com.greenantmall.bean.PortalItemData;
import com.greenantmall.bean.StoreInfo;
import com.greenantmall.bean.UIBanners;
import com.greenantmall.bean.UIGoods;
import com.greenantmall.bean.UIGoodsCategory;
import com.greenantmall.bean.UIGoodsRecommend;
import com.greenantmall.bean.UIRecommendByUs;
import com.greenantmall.service.RetrieveDataAsyn;
import com.greenantmall.service.RetrieveDataListener;
import com.greenantmall.utils.Const;
import com.greenantmall.utils.UtilTools;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnPullEventListener;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshBase.State;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

public class TabFragmentHome extends Fragment implements
		OnRefreshListener<ListView>, OnPullEventListener<ListView>, OnItemClickListener {
	private ProgressBar mProgressBar;
	private TextView mTvPrompt;
	private PullToRefreshListView mPullToRefreshListView;
	private PortalListViewAdapter mPortalListViewAdapter;
	private List<PortalItemData> mDataList = new ArrayList<PortalItemData>();

	private final int REQUEST_ID_BANNERS = 1;
	private final int REQUEST_ID_TRADE = 2;
	private final int REQUEST_ID_HOME_PAGE_ITEM_1 = 3;
	private final int REQUEST_ID_HOME_PAGE_ITEM_2 = 4;
	private final int REQUEST_ID_HOME_PAGE_ITEM_3 = 5;
	private final int REQUEST_ID_HOME_PAGE_IMAGE_ITEMS = 6;

	private enum DataLoadResult {
		ResultLoadNormal, ResultLoading, ResultLoadSuccessful, ResultLoadFailed
	}

	private DataLoadResult mDataLoadResultForBanners = DataLoadResult.ResultLoadNormal;
	private DataLoadResult mDataLoadResultForTrade = DataLoadResult.ResultLoadNormal;
	private DataLoadResult mDataLoadResultForItem1 = DataLoadResult.ResultLoadNormal;
	private DataLoadResult mDataLoadResultForItem2 = DataLoadResult.ResultLoadNormal;
	private DataLoadResult mDataLoadResultForItem3 = DataLoadResult.ResultLoadNormal;
	private DataLoadResult mDataLoadResultForImageItem = DataLoadResult.ResultLoadNormal;

	private RetrieveDataListener1 mRetrieveDataListener1;
	
	public void reloadData() {
		mDataList.clear();
		mPortalListViewAdapter.notifyDataSetChanged();
		mRetrieveDataListener1 = new RetrieveDataListener1();
		mDataLoadResultForBanners = DataLoadResult.ResultLoadNormal;
		mDataLoadResultForTrade = DataLoadResult.ResultLoadNormal;
		mDataLoadResultForItem1 = DataLoadResult.ResultLoadNormal;
		mDataLoadResultForItem2 = DataLoadResult.ResultLoadNormal;
		mDataLoadResultForItem3 = DataLoadResult.ResultLoadNormal;
		mDataLoadResultForImageItem = DataLoadResult.ResultLoadNormal;
		this.refreshData();
	}

	@Override
	public void onRefresh(PullToRefreshBase<ListView> refreshView) {
		this.refreshData();
		// mSlidingMenuManage.setCanScroll(true);
	}

	@Override
	public void onPullEvent(PullToRefreshBase<ListView> refreshView,
			State state, Mode direction) {
		Log.d("CEXX", "CEXX => TabFragmentHome => onPullEvent => state : "
				+ state);
		if (State.PULL_TO_REFRESH.equals(state)) {
			// mSlidingMenuManage.setCanScroll(false);
		} else if (State.RESET.equals(state)) {
			// mSlidingMenuManage.setCanScroll(true);
		}
	}

	public void refreshData() {
		if (isLoading()) {
			mPullToRefreshListView.onRefreshComplete();
			return;
		}

		mProgressBar.setVisibility(View.VISIBLE);
		mTvPrompt.setVisibility(View.GONE);
		mDataLoadResultForBanners = DataLoadResult.ResultLoading;
		mDataLoadResultForTrade = DataLoadResult.ResultLoading;
		mDataLoadResultForItem1 = DataLoadResult.ResultLoading;
		mDataLoadResultForItem2 = DataLoadResult.ResultLoading;
		mDataLoadResultForItem3 = DataLoadResult.ResultLoading;
		mDataLoadResultForImageItem = DataLoadResult.ResultLoading;
		
		// banners
		RetrieveDataAsyn.getInstance().getBanners(REQUEST_ID_BANNERS,
				mRetrieveDataListener1);
		// trade style
		RetrieveDataAsyn.getInstance().getTradeStyle(
				AntHomeApplication.sectionNum, REQUEST_ID_TRADE,
				mRetrieveDataListener1);
		// home page image items
		RetrieveDataAsyn.getInstance().getGoodsRecommend(
				AntHomeApplication.sectionNum,
				REQUEST_ID_HOME_PAGE_IMAGE_ITEMS, mRetrieveDataListener1);
		// home page items
		RetrieveDataAsyn.getInstance().getRecommendByUs(
				AntHomeApplication.sectionNum, -1, new RetrieveDataListener() {
					@Override
					public void dataRetrieved(int requestId, Object data) {
						if (data != null) {
							boolean tag1 = true;
							boolean tag2 = true;
							boolean tag3 = true;
							List<UIRecommendByUs> rbuList = (List<UIRecommendByUs>) data;
							for (UIRecommendByUs rbu : rbuList) {
								switch (rbu.getShowIndex()) {
								case 1:
									RetrieveDataAsyn
											.getInstance()
											.getGoodsCvsStoreRecommend(Const.mStoreInfoCvs, 
													REQUEST_ID_HOME_PAGE_ITEM_1, 
													new RetrieveDataListener2(rbu));
									tag1 = false;
									break;
								case 2:
									RetrieveDataAsyn
											.getInstance()
											.getGoodsByRecommendByUs(
													rbu.getObjectId(),
													AntHomeApplication.sectionNum,
													REQUEST_ID_HOME_PAGE_ITEM_2,
													new RetrieveDataListener2(rbu));
									tag2 = false;
									break;
								case 3:
									RetrieveDataAsyn
											.getInstance()
											.getGoodsByRecommendByUs(
													rbu.getObjectId(),
													AntHomeApplication.sectionNum,
													REQUEST_ID_HOME_PAGE_ITEM_3,
													new RetrieveDataListener2(rbu));
									tag3 = false;
									break;
								}
							}

							if (tag1) {
								mDataLoadResultForItem1 = DataLoadResult.ResultLoadFailed;
								List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
								for (PortalItemData pid : mDataList) {
									if (pid.mType == PortalItemData.TYPE_ITEM1_WITH_TITLE) {
										willBeRemovedList.add(pid);
									}
								}
								mDataList.removeAll(willBeRemovedList);
							}

							if (tag2) {
								mDataLoadResultForItem2 = DataLoadResult.ResultLoadFailed;
								List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
								for (PortalItemData pid : mDataList) {
									if (pid.mType == PortalItemData.TYPE_ITEM2_WITH_TITLE) {
										willBeRemovedList.add(pid);
									}
								}
								mDataList.removeAll(willBeRemovedList);
							}

							if (tag3) {
								mDataLoadResultForItem3 = DataLoadResult.ResultLoadFailed;
								List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
								for (PortalItemData pid : mDataList) {
									if (pid.mType == PortalItemData.TYPE_ITEM3
											|| pid.mType == PortalItemData.TYPE_ITEM3_WITH_TITLE) {
										willBeRemovedList.add(pid);
									}
								}
								mDataList.removeAll(willBeRemovedList);
							}

							if (tag1 || tag2 || tag3) {
								mPortalListViewAdapter.notifyDataSetChanged();
							}
						} else {
							mDataLoadResultForItem1 = DataLoadResult.ResultLoadFailed;
							mDataLoadResultForItem2 = DataLoadResult.ResultLoadFailed;
							mDataLoadResultForItem3 = DataLoadResult.ResultLoadFailed;
						}
						checkLoadFinished();
					}
				});
	}

	private class RetrieveDataListener1 implements RetrieveDataListener {
		private int sectionNumRecord;

		public RetrieveDataListener1() {
			sectionNumRecord = AntHomeApplication.sectionNum;
		}

		@Override
		public void dataRetrieved(int requestId, Object data) {
			Log.d("CEXX",
					"TabFragmentHome => RetrieveDataListener1 => dataRetrieved => sectionNumRecord : "
							+ sectionNumRecord);
			Log.d("CEXX",
					"TabFragmentHome => RetrieveDataListener1 => dataRetrieved => AntHomeApplication.sectionNum : "
							+ AntHomeApplication.sectionNum);
			if (sectionNumRecord != AntHomeApplication.sectionNum) {
				return;
			}

			Log.d("CEXX",
					"TabFragmentHome => RetrieveDataListener1 => dataRetrieved => requestId : "
							+ requestId);
			Log.d("CEXX",
					"TabFragmentHome => RetrieveDataListener1 => dataRetrieved => data==null : "
							+ (data == null));
			if (requestId == REQUEST_ID_BANNERS) {
				List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
				for (PortalItemData pid : mDataList) {
					if (pid.mType == PortalItemData.TYPE_BANNERS) {
						willBeRemovedList.add(pid);
					}
				}
				mDataList.removeAll(willBeRemovedList);

				if (data != null) {
					List<UIBanners> antBanners = (List<UIBanners>) data;
					if (antBanners.size() > 0) {
						PortalItemData itemData = new PortalItemData();
						itemData.mType = PortalItemData.TYPE_BANNERS;
						itemData.mDataObj = data;
						mDataList.add(itemData);
					}

					mDataLoadResultForBanners = DataLoadResult.ResultLoadSuccessful;
				} else {
					mDataLoadResultForBanners = DataLoadResult.ResultLoadFailed;
				}

				Collections.sort(mDataList, new Comparator<PortalItemData>() {
					@Override
					public int compare(PortalItemData lhs, PortalItemData rhs) {
						return lhs.mType - rhs.mType;
					}
				});
				mPortalListViewAdapter.notifyDataSetChanged();
			} else if (requestId == REQUEST_ID_TRADE) {
				List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
				for (PortalItemData pid : mDataList) {
					if (pid.mType == PortalItemData.TYPE_TRADE) {
						willBeRemovedList.add(pid);
					}
				}
				mDataList.removeAll(willBeRemovedList);

				if (data != null) {
					List<UIGoodsCategory> totalList = (List<UIGoodsCategory>) data;
					int size = totalList.size();
					int m = size / 4;
					int n = size % 4;
					Log.d("CEXX",
							"TabFragmentHome => RetrieveDataListener1 => dataRetrieved => REQUEST_ID_TRADE => size : "
									+ size);
					Log.d("CEXX",
							"TabFragmentHome => RetrieveDataListener1 => dataRetrieved => REQUEST_ID_TRADE => m : "
									+ m);
					Log.d("CEXX",
							"TabFragmentHome => RetrieveDataListener1 => dataRetrieved => REQUEST_ID_TRADE => n : "
									+ n);

					for (int i = 0; i < m; i++) {
						List<UIGoodsCategory> itemList = new ArrayList<UIGoodsCategory>();
						for (int j = 4 * i; j < 4 * i + 4; j++) {
							itemList.add(totalList.get(j));
						}
						PortalItemData itemData = new PortalItemData();
						itemData.mType = PortalItemData.TYPE_TRADE;
						itemData.mDataObj = itemList;
						mDataList.add(itemData);
					}

					List<UIGoodsCategory> itemList = new ArrayList<UIGoodsCategory>();
					for (int i = 4 * m; i < 4 * m + n; i++) {
						itemList.add(totalList.get(i));
					}
					if (itemList.size() > 0) {
						PortalItemData itemData = new PortalItemData();
						itemData.mType = PortalItemData.TYPE_TRADE;
						itemData.mDataObj = itemList;
						mDataList.add(itemData);
					}

					mDataLoadResultForTrade = DataLoadResult.ResultLoadSuccessful;
				} else {
					mDataLoadResultForTrade = DataLoadResult.ResultLoadFailed;
				}

				Collections.sort(mDataList, new Comparator<PortalItemData>() {
					@Override
					public int compare(PortalItemData lhs, PortalItemData rhs) {
						return lhs.mType - rhs.mType;
					}
				});
				mPortalListViewAdapter.notifyDataSetChanged();
			} else if (requestId == REQUEST_ID_HOME_PAGE_IMAGE_ITEMS) {
				List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
				for (PortalItemData pid : mDataList) {
					if (pid.mType == PortalItemData.TYPE_ITEM_IMAGE) {
						willBeRemovedList.add(pid);
					}
				}
				mDataList.removeAll(willBeRemovedList);

				if (data != null) {
					List<UIGoodsRecommend> list = (List<UIGoodsRecommend>) data;
					if (list.size() > 0) {
						PortalItemData itemData = new PortalItemData();
						itemData.mType = PortalItemData.TYPE_ITEM_IMAGE;
						itemData.mDataObj = data;
						mDataList.add(itemData);
					}

					mDataLoadResultForImageItem = DataLoadResult.ResultLoadSuccessful;
				} else {
					mDataLoadResultForImageItem = DataLoadResult.ResultLoadFailed;
				}

				Collections.sort(mDataList, new Comparator<PortalItemData>() {
					@Override
					public int compare(PortalItemData lhs, PortalItemData rhs) {
						return lhs.mType - rhs.mType;
					}
				});
				mPortalListViewAdapter.notifyDataSetChanged();
			}
			checkLoadFinished();
		}
	}

	private class RetrieveDataListener2 implements RetrieveDataListener {
		private UIRecommendByUs mUIRecommendByUs;
		private int sectionNumRecord;

		public RetrieveDataListener2(UIRecommendByUs uiRecommendByUs) {
			mUIRecommendByUs = uiRecommendByUs;
			sectionNumRecord = AntHomeApplication.sectionNum;
		}

		@Override
		public void dataRetrieved(int requestId, Object data) {
			Log.d("CEXX",
					"TabFragmentHome => RetrieveDataListener2 => dataRetrieved => sectionNumRecord : "
							+ sectionNumRecord);
			Log.d("CEXX",
					"TabFragmentHome => RetrieveDataListener2 => dataRetrieved => AntHomeApplication.sectionNum : "
							+ AntHomeApplication.sectionNum);
			if (sectionNumRecord != AntHomeApplication.sectionNum) {
				return;
			}

			Log.d("CEXX",
					"TabFragmentHome => RetrieveDataListener2 => dataRetrieved => requestId : "
							+ requestId);
			Log.d("CEXX",
					"TabFragmentHome => RetrieveDataListener2 => dataRetrieved => data==null : "
							+ (data == null));

			if (requestId == REQUEST_ID_HOME_PAGE_ITEM_1) {
				List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
				for (PortalItemData pid : mDataList) {
					if (pid.mType == PortalItemData.TYPE_ITEM1_WITH_TITLE) {
						willBeRemovedList.add(pid);
					}
				}
				mDataList.removeAll(willBeRemovedList);

				if (AVUser.getCurrentUser() != null && data != null) {
					List<UIGoods> listItem1 = (List<UIGoods>) data;
					if (listItem1.size() > 0) {
						PortalItemData itemData = new PortalItemData();
						itemData.mType = PortalItemData.TYPE_ITEM1_WITH_TITLE;
						itemData.mDataObj = listItem1;
						itemData.mTitleIconUrl = mUIRecommendByUs
								.getTitleIconUrl();
						itemData.mTitleDes = mUIRecommendByUs.getTitleDes();
						mDataList.add(itemData);
					}

					mDataLoadResultForItem1 = DataLoadResult.ResultLoadSuccessful;
				} else {
					mDataLoadResultForItem1 = DataLoadResult.ResultLoadFailed;
				}

				Collections.sort(mDataList, new Comparator<PortalItemData>() {
					@Override
					public int compare(PortalItemData lhs, PortalItemData rhs) {
						return lhs.mType - rhs.mType;
					}
				});
				mPortalListViewAdapter.notifyDataSetChanged();
			} else if (requestId == REQUEST_ID_HOME_PAGE_ITEM_2) {
				List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
				for (PortalItemData pid : mDataList) {
					if (pid.mType == PortalItemData.TYPE_ITEM2_WITH_TITLE) {
						willBeRemovedList.add(pid);
					}
				}
				mDataList.removeAll(willBeRemovedList);

				if (data != null) {
					List<UIGoods> listItem2 = (List<UIGoods>) data;
					if (listItem2.size() > 0) {
						PortalItemData itemData = new PortalItemData();
						itemData.mType = PortalItemData.TYPE_ITEM2_WITH_TITLE;
						itemData.mDataObj = listItem2;
						itemData.mTitleIconUrl = mUIRecommendByUs
								.getTitleIconUrl();
						itemData.mTitleDes = mUIRecommendByUs.getTitleDes();
						mDataList.add(itemData);
					}

					mDataLoadResultForItem2 = DataLoadResult.ResultLoadSuccessful;
				} else {
					mDataLoadResultForItem2 = DataLoadResult.ResultLoadFailed;
				}

				Collections.sort(mDataList, new Comparator<PortalItemData>() {
					@Override
					public int compare(PortalItemData lhs, PortalItemData rhs) {
						return lhs.mType - rhs.mType;
					}
				});
				mPortalListViewAdapter.notifyDataSetChanged();
			} else if (requestId == REQUEST_ID_HOME_PAGE_ITEM_3) {
				List<PortalItemData> willBeRemovedList = new ArrayList<PortalItemData>();
				for (PortalItemData pid : mDataList) {
					if (pid.mType == PortalItemData.TYPE_ITEM3
							|| pid.mType == PortalItemData.TYPE_ITEM3_WITH_TITLE) {
						willBeRemovedList.add(pid);
					}
				}
				mDataList.removeAll(willBeRemovedList);

				if (data != null) {
					List<UIGoods> listItem3 = (List<UIGoods>) data;
					if (listItem3.size() > 0) {
						// area item 3
						List<PortalItemData> tempPIDList = new ArrayList<PortalItemData>();
						List<UIGoods> tempGoodsList = null;
						for (UIGoods goods : listItem3) {
							if (tempGoodsList == null) {
								tempGoodsList = new ArrayList<UIGoods>();
							}

							tempGoodsList.add(goods);

							if (tempGoodsList.size() == 3) {
								PortalItemData itemData = new PortalItemData();
								itemData.mType = PortalItemData.TYPE_ITEM3;
								itemData.mDataObj = tempGoodsList;
								tempPIDList.add(itemData);
								itemData.mTitleIconUrl = mUIRecommendByUs
										.getTitleIconUrl();
								itemData.mTitleDes = mUIRecommendByUs
										.getTitleDes();
								tempGoodsList = null;
							}
						}

						if (tempGoodsList != null && tempGoodsList.size() > 0) {
							PortalItemData itemData = new PortalItemData();
							itemData.mType = PortalItemData.TYPE_ITEM3;
							itemData.mDataObj = tempGoodsList;
							tempPIDList.add(itemData);
							tempGoodsList = null;
						}

						if (tempPIDList.size() > 0) {
							tempPIDList.get(0).mType = PortalItemData.TYPE_ITEM3_WITH_TITLE;
							mDataList.addAll(tempPIDList);
						}
					}

					mDataLoadResultForItem3 = DataLoadResult.ResultLoadSuccessful;
				} else {
					mDataLoadResultForItem3 = DataLoadResult.ResultLoadFailed;
				}

				Collections.sort(mDataList, new Comparator<PortalItemData>() {
					@Override
					public int compare(PortalItemData lhs, PortalItemData rhs) {
						return lhs.mType - rhs.mType;
					}
				});
				mPortalListViewAdapter.notifyDataSetChanged();
			}
			checkLoadFinished();
		}
	}

	private boolean isLoading() {
		if (DataLoadResult.ResultLoading.equals(mDataLoadResultForBanners)
				|| DataLoadResult.ResultLoading.equals(mDataLoadResultForTrade)
				|| DataLoadResult.ResultLoading.equals(mDataLoadResultForItem1)
				|| DataLoadResult.ResultLoading.equals(mDataLoadResultForItem2)
				|| DataLoadResult.ResultLoading.equals(mDataLoadResultForItem3)
				|| DataLoadResult.ResultLoading
						.equals(mDataLoadResultForImageItem)) {
			return true;
		}
		return false;
	}

	private void checkLoadFinished() {
		if (DataLoadResult.ResultLoadSuccessful
				.equals(mDataLoadResultForBanners)
				|| DataLoadResult.ResultLoadSuccessful
						.equals(mDataLoadResultForTrade)
				|| DataLoadResult.ResultLoadSuccessful
						.equals(mDataLoadResultForItem1)
				|| DataLoadResult.ResultLoadSuccessful
						.equals(mDataLoadResultForItem2)
				|| DataLoadResult.ResultLoadSuccessful
						.equals(mDataLoadResultForItem3)
				|| DataLoadResult.ResultLoadSuccessful
						.equals(mDataLoadResultForImageItem)) {
			mProgressBar.setVisibility(View.GONE);
			// mPullToRefreshListView.setVisibility(View.VISIBLE);
		}

		if (!DataLoadResult.ResultLoading.equals(mDataLoadResultForBanners)
				&& !DataLoadResult.ResultLoading
						.equals(mDataLoadResultForTrade)
				&& !DataLoadResult.ResultLoading
						.equals(mDataLoadResultForItem1)
				&& !DataLoadResult.ResultLoading
						.equals(mDataLoadResultForItem2)
				&& !DataLoadResult.ResultLoading
						.equals(mDataLoadResultForItem3)
				&& !DataLoadResult.ResultLoading
						.equals(mDataLoadResultForImageItem)) {
			mProgressBar.setVisibility(View.GONE);
			mPullToRefreshListView.onRefreshComplete();
			
			// 添加notice
			for(PortalItemData itemData : mDataList) {
				if(itemData.mType == PortalItemData.TYPE_NOTICE) {
					mDataList.remove(itemData);
					break;
				}
			}
			StoreInfo storeInfoCvs = Const.mStoreInfoCvs;
			if(AVUser.getCurrentUser() != null && storeInfoCvs != null) {
				Log.d("CEXX", "CEXX ---> notice ---> storeInfoCvs.getStoreNotice : " + storeInfoCvs.getStoreNotice());
				if(!TextUtils.isEmpty(storeInfoCvs.getStoreNotice())) {
					PortalItemData noticeItemData = new PortalItemData();
					noticeItemData.mType = PortalItemData.TYPE_NOTICE;
					noticeItemData.mDataObj = storeInfoCvs.getStoreNotice();
					mDataList.add(noticeItemData);
				}
			}
			Collections.sort(mDataList, new Comparator<PortalItemData>() {
				@Override
				public int compare(PortalItemData lhs, PortalItemData rhs) {
					return lhs.mType - rhs.mType;
				}
			});
			mPortalListViewAdapter.notifyDataSetChanged();
			
			if (mDataList.size() == 0) {
				// mPullToRefreshListView.setVisibility(View.GONE);
				mTvPrompt.setVisibility(View.VISIBLE);
				mTvPrompt.setText(getResources().getString(
						R.string.portal_data_load_error));
			} else {
				// mPullToRefreshListView.setVisibility(View.VISIBLE);
				mTvPrompt.setVisibility(View.GONE);
			}
		}
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d("CEXX", "CEXX => TabFragmentHome => onCreate");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		Log.d("CEXX", "CEXX => TabFragmentHome => onCreateView");
		return inflater.inflate(R.layout.tab_fragment_home, container, false);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		Log.d("CEXX", "CEXX => TabFragmentHome => onViewCreated");

		mProgressBar = (ProgressBar) view.findViewById(R.id.portal_prgressbar);
		mTvPrompt = (TextView) view.findViewById(R.id.portal_tv_prompt);
		mPullToRefreshListView = (PullToRefreshListView) view
				.findViewById(R.id.portal_listview);

		mPullToRefreshListView.setOnItemClickListener(this);
		mPullToRefreshListView.setOnRefreshListener(this);
		mPullToRefreshListView.setOnPullEventListener(this);
		mPortalListViewAdapter = new PortalListViewAdapter(getActivity(),
				mDataList);
		mPullToRefreshListView.setAdapter(mPortalListViewAdapter);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		Log.d("CEXX", "CEXX => TabFragmentHome => onActivityCreated");

		mRetrieveDataListener1 = new RetrieveDataListener1();
		this.refreshData();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		Log.d("CEXX", "CEXX => TabFragmentHome => onDestroy");
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
	}
}
